﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Collections;
using ElingOA6_Admin_DSJCJ.Common;
using DevExpress.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using DevExpress.Web.ASPxScheduler;
using DevExpress.XtraScheduler;
using Newtonsoft.Json;

namespace ElingOA6_Admin_DSJCJ.Areas.Admin.Controllers
{

    [OutputCache(Duration = 0, VaryByParam = "none")]
    public class CalendarController : AdminBaseController
    {
        //
        // GET: /Admin/Calendar/
        public BLL.HREmpl empbll = new BLL.HREmpl();
        public string entityNo = GlobalConstant.ENTITYNO;
        public BLL.Calendar calendarbll = new BLL.Calendar();
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        /// 
        [AuthorityActionFilter("m_Calendar", Order = 1)]
        [LogPageActionFilter("日历管理", Order = 2)]
        public ActionResult Index()
        {
            //获取员工表
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);

            Model.HREmpl memp = empbll.GetModel(entityNo, emplNo);
            List<Model.HREmpl> emplist = new List<Model.HREmpl>();
            emplist.Add(memp);
            //  emplist = empbll.GetEmplList(entityNo);
            //获取日历表
            List<Model.Calendar> calendarlist = calendarbll.GetModelList("FEmplNo='" + emplNo + "'");
            Session["time"] = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            ViewData["rmdcdr"] = calendarbll.GetModelList("FEmplNo='" + emplNo + "' and FNextWakeTime is not null").Where(h => h.FNextWakeTime < DateTime.Now).OrderBy(h => h.FPri).ToList();

            return View("Index", new SchedulerDataObject() { Appointments = calendarlist.ToList(), Resources = emplist.ToList() });
        }
        /// <summary>
        /// 删除单个日历项
        /// </summary>
        /// <param name="cid">id</param>
        /// <returns></returns>
        public string DeleteCalendarOne(string cid)
        {
            try
            {
                calendarbll.Delete(decimal.Parse(cid));
                return "ok";
            }
            catch (System.Exception ex)
            {
                return "错误代码:" + ex.Message;
            }
        }
        /// <summary>
        /// ajax获取下拉框
        /// </summary>
        /// <param name="cval"></param>
        /// <returns></returns>
        public string GetComboboxList(string cval)
        {
            try
            {
                List<SelectListItem> ls = new List<SelectListItem> { 
	                         
	                           new SelectListItem { Text = "0分钟", Value = "0m" },
	
	                           new SelectListItem { Text = "5分钟", Value = "5m" },
	                           new SelectListItem { Text = "10分钟", Value = "10m" },
	                           new SelectListItem { Text = "15分钟", Value = "15m" },
	                           new SelectListItem { Text = "30分钟", Value = "30m" },
	                           new SelectListItem { Text = "1小时", Value = "1h" },
	                             new SelectListItem { Text = "3小时", Value = "3h" },
	                               new SelectListItem { Text = "5小时", Value = "5h" },
	                                 new SelectListItem { Text = "10小时", Value = "10h" },
	                                  new SelectListItem { Text = "1天", Value = "1d" },
	                                   new SelectListItem { Text = "2天", Value = "2d" },
	                                    new SelectListItem { Text = "3天", Value = "3d" },
	                                     new SelectListItem { Text = "5天", Value = "5d" },
	                                     new SelectListItem { Text = "10天", Value = "5d"} 
	     };
                //取对应的日历项 
                Model.Calendar c = calendarbll.GetModel(decimal.Parse(cval));

                if (c.FBeginDate > DateTime.Now)
                {
                    List<SelectListItem> lsa = new List<SelectListItem>() { 
	                         
	                           new SelectListItem { Text = "开始前15分钟", Value = "-15m" },
	
	                           new SelectListItem { Text = "开始前10分钟", Value = "-10m" },
	                           new SelectListItem { Text = "开始前5分钟", Value = "-5m" },
	                           new SelectListItem { Text = "开始前0小时", Value = "0h" } };
                    lsa.AddRange(ls);


                    return JsonConvert.SerializeObject(lsa);
                }
                else
                {
                    return JsonConvert.SerializeObject(ls);
                }


            }
            catch (System.Exception ex)
            {
                return "错误代码:" + ex.Message;
            }
            ;
        }
        /// <summary>
        /// 保存日历项
        /// </summary>
        /// <param name="c">日历项</param>
        /// <returns></returns>
        public string Save(Model.Calendar c)
        {
            if (c.FBeginDate > c.FEndDate)
            {
                return "错误:起始日期必须小于结束日期,请重新填写";
            }
            if (c.FIsAllDayEvent == "True" & (c.FBeginDate.Hour != 0 | c.FBeginDate.Minute != 0 | c.FBeginDate.Second != 0 | c.FEndDate.Hour != 0 | c.FEndDate.Millisecond != 0 | c.FEndDate.Second != 0 ))
            {
                return "错误:全天事件必须为所选日期0:00-0:00";
            }
            
            //取当前员工
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
            try
            {

                if (!string.IsNullOrEmpty(c.FCalendarID.ToString()))
                {
                    if (calendarbll.Exists(c.FCalendarID))
                    {
                        //先判断员工是否存在,存在则更新
                        c.FInputTime = DateTime.Now;
                        c.FEntityNo = entityNo;
                        c.FEmplNo = emplNo;
                        //判断字段全天
                        string iall = c.FIsAllDayEvent;
                        if (iall == "True")
                        {
                            c.FIsAllDayEvent = "Y";
                        }
                        else
                        {
                            c.FIsAllDayEvent = "N";
                        }
                        //  string isw = c.FIsWake;
                        //if (isw=="True")
                        //{
                        //    c.FIsWake = "Y";
                        //    c.FNextWakeTime = c.FBeginDate;
                        //} 
                        //else
                        //{
                        //    c.FIsWake = "N";
                        //}
                        //判断提醒时间,m=分,h=小时,d=tian
                        string rmdv = ComboBoxExtension.GetValue<String>("rmdcombobox");
                        computenextwaketime(c, rmdv);
                        //判断优先级
                        string prv = ComboBoxExtension.GetValue<string>("pricombobox");
                        if (prv != "none")
                        {
                            c.FPri = prv;
                        }
                        calendarbll.Update(c);
                        ViewData["jsAlert"] = "更新成功";
                        Model.HREmpl memp = empbll.GetModel(entityNo, emplNo);
                        List<Model.HREmpl> emplist = new List<Model.HREmpl>();
                        emplist.Add(memp);
                        // Session["time"] = c.FBeginDate;
                        //  emplist = empbll.GetEmplList(entityNo);
                        List<Model.Calendar> calendarlist = calendarbll.GetModelList("FEmplNo='" + emplNo + "'");
                        ViewData["rmdcdr"] = calendarbll.GetModelList("FEmplNo='" + emplNo + "' and FNextWakeTime is not null").Where(h => h.FNextWakeTime < DateTime.Now).OrderBy(h => h.FPri).ToList();
                        List<Model.Calendar> mcs = calendarbll.GetModelList("FEmplNo='" + emplNo + "' and FNextWakeTime is not null").Where(h => h.FNextWakeTime < DateTime.Now).OrderBy(h => h.FPri).ToList();
                        //返回ajaxjson结果
                        string success = JsonConvert.SerializeObject(mcs);


                        return success;

                        //  return View("Index", new SchedulerDataObject() { Appointments = calendarlist.ToList(), Resources = emplist.ToList() });
                    }
                    else
                    {
                        //不存在则新增日历数据
                        c.FInputTime = DateTime.Now;
                        c.FEntityNo = entityNo;
                        c.FEmplNo = emplNo;
                        //判断字段全天
                        string iall = c.FIsAllDayEvent;
                        if (iall == "True")
                        {
                            c.FIsAllDayEvent = "Y";
                        }
                        else
                        {
                            c.FIsAllDayEvent = "N";
                        }
                        string isw = c.FIsWake;
                        //if (isw == "True")
                        //{
                        //    c.FIsWake = "Y";
                        //    c.FNextWakeTime = c.FBeginDate;
                        //}
                        //else
                        //{
                        //    c.FIsWake = "N";
                        //}
                        //判断提醒时间,m=分,h=小时,d=tian
                        string rmdv = ComboBoxExtension.GetValue<String>("rmdcombobox");
                        computenextwaketime(c, rmdv);
                        //if (rmdv != "none")
                        //{
                        //    if (rmdv.ToString().Contains("m"))
                        //    {
                        //        string vl = rmdv.Substring(0, rmdv.IndexOf("m"));
                        //        c.FNextWakeTime = DateTime.Now.AddMinutes(double.Parse(vl));
                        //    }
                        //    else if (rmdv.ToString().Contains("h"))
                        //    {
                        //        string vl = rmdv.Substring(0, rmdv.IndexOf("h"));
                        //        c.FNextWakeTime = DateTime.Now.AddHours(double.Parse(vl));
                        //    }
                        //    else if (rmdv.ToString().Contains("d"))
                        //    {
                        //        string vl = rmdv.Substring(0, rmdv.IndexOf("d"));
                        //        c.FNextWakeTime = DateTime.Now.AddDays(double.Parse(vl));

                        //    }

                        //}
                        //判断优先级
                        string prv = ComboBoxExtension.GetValue<string>("pricombobox");
                        if (prv != "none")
                        {
                            c.FPri = prv;
                        }
                        decimal cout = calendarbll.Add(c);

                        Model.HREmpl memp = empbll.GetModel(entityNo, emplNo);
                        List<Model.HREmpl> emplist = new List<Model.HREmpl>();
                        emplist.Add(memp);
                        //  emplist = empbll.GetEmplList(entityNo);
                        List<Model.Calendar> calendarlist = calendarbll.GetModelList("FEmplNo='" + emplNo + "'");
                        ViewData["jsAlert"] = "新增成功";
                        // Session["time"] = c.FBeginDate;
                        ViewData["rmdcdr"] = calendarbll.GetModelList("FEmplNo='" + emplNo + "' and FNextWakeTime is not null").Where(h => h.FNextWakeTime < DateTime.Now).OrderBy(h => h.FPri).ToList();

                        //  return View("Index", new SchedulerDataObject() { Appointments = calendarlist.ToList(), Resources = emplist.ToList() });
                        List<Model.Calendar> mcs = calendarbll.GetModelList("FEmplNo='" + emplNo + "' and FNextWakeTime is not null").Where(h => h.FNextWakeTime < DateTime.Now).OrderBy(h => h.FPri).ToList();
                        string success = JsonConvert.SerializeObject(mcs);


                        return success;

                    }
                }
                else
                {

                    //不存在报错
                    ViewData["jsAlert"] = "添加失败:原因id不存在";
                    Model.HREmpl memp = empbll.GetModel(entityNo, emplNo);
                    List<Model.HREmpl> emplist = new List<Model.HREmpl>();
                    emplist.Add(memp);
                    // Session["time"] = DateTime.Now;
                    //  emplist = empbll.GetEmplList(entityNo);
                    List<Model.Calendar> calendarlist = calendarbll.GetModelList("FEmplNo='" + emplNo + "'");
                    ViewData["rmdcdr"] = calendarbll.GetModelList("FEmplNo='" + emplNo + "' and FNextWakeTime is not null").Where(h => h.FNextWakeTime < DateTime.Now).OrderBy(h => h.FPri).ToList();
                    List<Model.Calendar> mcs = calendarbll.GetModelList("FEmplNo='" + emplNo + "' and FNextWakeTime is not null").Where(h => h.FNextWakeTime < DateTime.Now).OrderBy(h => h.FPri).ToList();
                    string success = JsonConvert.SerializeObject(mcs);


                    return success;

                    //  return View("Index", new SchedulerDataObject() { Appointments = calendarlist.ToList(), Resources = emplist.ToList() });

                }
            }
            catch (Exception e)
            {
                // ViewBag.SchedulerErrorText = e.Message;
                return e.Message;
            }


        }
        /// <summary>
        /// 日历查看页面
        /// </summary>
        /// <param name="cid">主键id</param>
        /// <returns></returns>
        public ActionResult CalendarLook(string cid)
        {

            Model.Calendar c = calendarbll.GetModel(decimal.Parse(cid));
            return View("calendarlook", c);
        }


        /// <summary>
        /// 计算提醒时间
        /// </summary>
        /// <param name="c">model</param>
        /// <param name="rmdv">时间值</param>
        private static void computenextwaketime(Model.Calendar c, string rmdv)
        {
            TimeSpan tp = new TimeSpan();
            if (rmdv != "none")
            {
                if (rmdv.ToString().Contains("m"))
                {
                    string vl = rmdv.Substring(0, rmdv.IndexOf("m"));
                    tp = new TimeSpan(0, int.Parse(vl), 0);
                    c.FWakeMinutes = (int)Math.Round(tp.TotalMinutes, 0);
                    c.FNextWakeTime = c.FBeginDate.AddMinutes(-double.Parse(vl));
                }
                else if (rmdv.ToString().Contains("h"))
                {
                    string vl = rmdv.Substring(0, rmdv.IndexOf("h"));
                    c.FNextWakeTime = c.FBeginDate.AddHours(-double.Parse(vl));
                    tp = new TimeSpan(int.Parse(vl), 0, 0);
                    c.FWakeMinutes = (int)Math.Round(tp.TotalMinutes, 0);
                }
                else if (rmdv.ToString().Contains("d"))
                {
                    string vl = rmdv.Substring(0, rmdv.IndexOf("d"));
                    c.FNextWakeTime = c.FBeginDate.AddDays(-double.Parse(vl));
                    tp = new TimeSpan(int.Parse(vl), 0, 0, 0);
                    c.FWakeMinutes = (int)Math.Round(tp.TotalMinutes, 0);
                }



            }
        }
        /// <summary>
        /// 保存提醒项
        /// ajaxform
        /// </summary>
        /// <returns>string</returns>
        public string SaveRemind()
        {
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);

            Model.HREmpl memp = empbll.GetModel(entityNo, emplNo);
            List<Model.HREmpl> emplist = new List<Model.HREmpl>();
            emplist.Add(memp);
            //  emplist = empbll.GetEmplList(entityNo);
            //获取日历表

            List<ElingOA6_Admin_DSJCJ.Model.Calendar> cs = calendarbll.GetModelList("FEmplNo='" + emplNo + "' and FNextWakeTime is not null").Where(h => h.FNextWakeTime < DateTime.Now).ToList();

            //  List<ElingOA6_Admin_DSJCJ.Model.Calendar> cs = calendarbll.GetModelList("").Where(h => h.FNextWakeTime<DateTime.Now).ToList();
            //获取所有选中id
            try
            {
                string[] ids = ListBoxExtension.GetSelectedValues<string>("FTitles");
                //所有延迟时间
                string rmdv = ComboBoxExtension.GetValue<string>("rmdcombobox");
                string rtype = Fetch.Post("htype");

                switch (rtype)
                {
                    //选中延迟
                    case "0":
                        List<Model.Calendar> snoozecdrs = new List<Model.Calendar>();
                        foreach (string s in ids)
                        {
                            Model.Calendar cdr = calendarbll.GetModel(decimal.Parse(s));
                            snoozecdrs.Add(cdr);
                        }
                        foreach (Model.Calendar c in snoozecdrs)
                        {
                            c.FLastWakeTime = DateTime.Now;
                            if (rmdv != "none")
                            {//各种推迟时间判断
                                if (rmdv.ToString().Contains("m"))
                                {
                                    string vl = rmdv.Substring(0, rmdv.IndexOf("m"));
                                    if (double.Parse(vl) <= 0)
                                    {
                                        c.FNextWakeTime = c.FBeginDate.AddMinutes(double.Parse(vl));
                                    }
                                    else
                                    {

                                        c.FNextWakeTime = DateTime.Now.AddMinutes(double.Parse(vl));
                                    }
                                }
                                else if (rmdv.ToString().Contains("h"))
                                {
                                    string vl = rmdv.Substring(0, rmdv.IndexOf("h"));
                                    if (double.Parse(vl) <= 0)
                                    {
                                        c.FNextWakeTime = c.FBeginDate.AddHours(double.Parse(vl));
                                    }
                                    else
                                    {


                                        c.FNextWakeTime = DateTime.Now.AddHours(double.Parse(vl));
                                    }
                                }
                                else if (rmdv.ToString().Contains("d"))
                                {
                                    string vl = rmdv.Substring(0, rmdv.IndexOf("d"));
                                    if (double.Parse(vl) <= 0)
                                    {
                                        c.FNextWakeTime = c.FBeginDate.AddDays(double.Parse(vl));
                                    }
                                    else
                                    {
                                        c.FNextWakeTime = DateTime.Now.AddDays(double.Parse(vl));

                                    }
                                }

                            }
                            calendarbll.Update(c);
                        }

                        break;
                    case "1":
                        //需要消除的日历项
                        List<Model.Calendar> dismisscdrs = new List<Model.Calendar>();
                        foreach (string s in ids)
                        {
                            Model.Calendar cdr = calendarbll.GetModel(decimal.Parse(s));
                            dismisscdrs.Add(cdr);
                        }
                        foreach (Model.Calendar c in dismisscdrs)
                        {
                            c.FLastWakeTime = DateTime.Now;
                            c.FNextWakeTime = DateTime.MaxValue;
                            calendarbll.Update(c);
                        }
                        break;
                    //全部消除
                    case "2":
                        foreach (Model.Calendar c in cs)
                        {
                            c.FLastWakeTime = DateTime.Now;
                            c.FNextWakeTime = DateTime.MaxValue;
                            calendarbll.Update(c);
                        }
                        break;
                    default:
                        foreach (Model.Calendar c in cs)
                        {
                            c.FLastWakeTime = DateTime.Now;
                            c.FNextWakeTime = DateTime.MaxValue;
                            calendarbll.Update(c);
                        }
                        break;

                }
                ViewBag.Msg = "ok";
                //返回全部更新数据
                List<Model.Calendar> mcs = calendarbll.GetModelList("FEmplNo='" + emplNo + "' and FNextWakeTime is not null").Where(h => h.FNextWakeTime < DateTime.Now).OrderBy(h => h.FPri).ToList();
                string success = JsonConvert.SerializeObject(mcs);


                return success;
            }
            catch (System.Exception ex)
            {
                ViewBag.Msg = "错误代码:" + ex.Message.ToString();
                // return remindpopup();
                // ActionResult ac = this.Index();
                return "错误代码:" + ex.Message.ToString();
            }

        }
        /// <summary>
        /// 返回轮询数据
        /// </summary>
        /// <returns></returns>
        public string needremind()
        {
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);

            List<Model.Calendar> mcs = calendarbll.GetModelList("FEmplNo='" + emplNo + "' and FNextWakeTime is not null").Where(h => h.FNextWakeTime < DateTime.Now).OrderBy(h => h.FPri).ToList();
            if (mcs.Count > 0)
            {
                string success = JsonConvert.SerializeObject(mcs);


                return success;
            }
            else
            {
                return "no";
            }
        }
        /// <summary>
        /// 提醒试图
        /// </summary>
        /// <returns></returns>

        public ActionResult remindpopup()
        {
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);

            Model.HREmpl memp = empbll.GetModel(entityNo, emplNo);
            List<Model.HREmpl> emplist = new List<Model.HREmpl>();
            emplist.Add(memp);
            //  emplist = empbll.GetEmplList(entityNo);
            //获取日历表提醒数据

            List<ElingOA6_Admin_DSJCJ.Model.Calendar> c = calendarbll.GetModelList("FEmplNo='" + emplNo + "' and FNextWakeTime is not null").Where(h => h.FNextWakeTime < DateTime.Now).OrderBy(h => h.FPri).ToList();
            return View("remindpopup", c);
        }

        /// <summary>
        /// 日历编辑时回调函数
        /// </summary>
        /// <returns></returns>
        public ActionResult CustomFormsPartialEditAppointment()
        {
            try
            {


                //三个方法必须都执行要不返回不了值;
                InsertAppointment();
                UpdateAppointments();
                DeleteAppointments();


                //重新获取数据return
                string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);
                Model.HREmpl memp = empbll.GetModel(entityNo, emplNo);
                List<Model.HREmpl> emplist = new List<Model.HREmpl>();
                emplist.Add(memp);
                //  emplist = empbll.GetEmplList(entityNo);
                List<Model.Calendar> calendarlist = calendarbll.GetModelList("FEmplNo='" + emplNo + "'");
                ViewData["jsAlert"] = "删除成功";

                return PartialView("ReportTemplatesPartial", new SchedulerDataObject() { Appointments = calendarlist.ToList(), Resources = emplist.ToList() });


                //int a = 1;
            }
            catch (Exception e)
            {
                ViewBag.SchedulerErrorText = e.Message;
            }

            return null;
        }

        /// <summary>
        /// 插入方法
        /// </summary>
        public void InsertAppointment()
        {

            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);

            Model.HREmpl memp = empbll.GetModel(entityNo, emplNo);
            List<Model.HREmpl> emplist = new List<Model.HREmpl>();
            emplist.Add(memp);
            //  emplist = empbll.GetEmplList(entityNo);
            List<Model.Calendar> calendarlist = calendarbll.GetModelList("FEmplNo='" + emplNo + "'");

            SchedulerDataObject EditableDataObject = new SchedulerDataObject() { Appointments = calendarlist.ToList(), Resources = emplist.ToList() };

            ElingOA6_Admin_DSJCJ.Model.Calendar carScheduling = GetAppointmentToInsert<ElingOA6_Admin_DSJCJ.Model.Calendar>(EditableDataObject, SchedulerDemoHelper.DefaultAppointmentStorage);
            int a = 0;
            // CarsDataProvider.InsertSchedule<ElingOA6_Admin_DSJCJ.Model.Calendar>(carScheduling);
        }

        /// <summary>
        /// 更新方法
        /// </summary>
        public void UpdateAppointments()
        {
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);

            Model.HREmpl memp = empbll.GetModel(entityNo, emplNo);
            List<Model.HREmpl> emplist = new List<Model.HREmpl>();
            emplist.Add(memp);
            //  emplist = empbll.GetEmplList(entityNo);
            List<Model.Calendar> calendarlist = calendarbll.GetModelList("FEmplNo='" + emplNo + "'");

            SchedulerDataObject EditableDataObject = new SchedulerDataObject() { Appointments = calendarlist.ToList(), Resources = emplist.ToList() };

            ElingOA6_Admin_DSJCJ.Model.Calendar[] carScheduling = GetAppointmentsToUpdate<ElingOA6_Admin_DSJCJ.Model.Calendar>(EditableDataObject, SchedulerDemoHelper.DefaultAppointmentStorage);
            foreach (ElingOA6_Admin_DSJCJ.Model.Calendar schedule in carScheduling)
            {
                if (calendarbll.Exists(schedule.FCalendarID))
                {
                    calendarbll.Update(schedule);
                }
                //int a = 0;
                // CarsDataProvider.UpdateSchedule<ElingOA6_Admin_DSJCJ.Model.Calendar>(schedule);
            }
        }
        /// <summary>
        /// 删除方法
        /// </summary>
        public void DeleteAppointments()
        {
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);

            Model.HREmpl memp = empbll.GetModel(entityNo, emplNo);
            List<Model.HREmpl> emplist = new List<Model.HREmpl>();
            emplist.Add(memp);
            //  emplist = empbll.GetEmplList(entityNo);
            List<Model.Calendar> calendarlist = calendarbll.GetModelList("FEmplNo='" + emplNo + "'");

            SchedulerDataObject EditableDataObject = new SchedulerDataObject() { Appointments = calendarlist.ToList(), Resources = emplist.ToList() };

            ElingOA6_Admin_DSJCJ.Model.Calendar[] carSchedulings = GetAppointmentsToRemove<ElingOA6_Admin_DSJCJ.Model.Calendar>(EditableDataObject, SchedulerDemoHelper.DefaultAppointmentStorage);
            foreach (ElingOA6_Admin_DSJCJ.Model.Calendar schedule in carSchedulings)
            {
                // CarsDataProvider.DeleteCarScheduling<ElingOA6_Admin_DSJCJ.Model.Calendar>(schedule);
                //根据id删除
                calendarbll.Delete(schedule.FCalendarID);
                int a = 0;
            }
        }

        /// <summary>
        /// 3个调用extension的方法
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="dataObject"></param>
        /// <param name="appointmentStorage"></param>
        /// <returns></returns>
        public static T GetAppointmentToInsert<T>(SchedulerDataObject dataObject, MVCxAppointmentStorage appointmentStorage)
        {
            return SchedulerExtension.GetAppointmentToInsert<T>("scheduler", dataObject.Appointments, dataObject.Resources,
                appointmentStorage, SchedulerDemoHelper.DefaultResourceStorage);
        }
        public static T[] GetAppointmentsToUpdate<T>(SchedulerDataObject dataObject, MVCxAppointmentStorage appointmentStorage)
        {
            return SchedulerExtension.GetAppointmentsToUpdate<T>("scheduler", dataObject.Appointments, dataObject.Resources,
                appointmentStorage, SchedulerDemoHelper.DefaultResourceStorage);
        }
        public static T[] GetAppointmentsToRemove<T>(SchedulerDataObject dataObject, MVCxAppointmentStorage appointmentStorage)
        {
            return SchedulerExtension.GetAppointmentsToRemove<T>("scheduler", dataObject.Appointments, dataObject.Resources,
                appointmentStorage, SchedulerDemoHelper.DefaultResourceStorage);
        }
        //分部试图回调函数
        public ActionResult ReportTemplatesPartial()
        {
            string emplNo = OperateSession.get(GlobalConstant.PARAM_FEMPLNO);

            Model.HREmpl memp = empbll.GetModel(entityNo, emplNo);
            List<Model.HREmpl> emplist = new List<Model.HREmpl>();
            emplist.Add(memp);

            List<Model.Calendar> calendarlist = calendarbll.GetModelList("FEmplNo='" + emplNo + "'");
            return PartialView(new SchedulerDataObject() { Appointments = calendarlist.ToList(), Resources = emplist.ToList() });
        }




    }

    /// <summary>
    /// 日历类
    /// </summary>
    public class SchedulerDataObject
    {
        public IEnumerable Appointments { get; set; }
        public IEnumerable Resources { get; set; }
    }

    public class SchedulerDemoHelper
    {
        public const string ImageQueryKey = "DXImage";

        public static string GetCarImageRouteUrl()
        {
            return DevExpressHelper.GetUrl(new { Controller = "Scheduler", Action = "CarImage" });
        }

        static MVCxAppointmentStorage defaultAppointmentStorage;
        public static MVCxAppointmentStorage DefaultAppointmentStorage
        {
            get
            {
                if (defaultAppointmentStorage == null)
                    defaultAppointmentStorage = CreateDefaultAppointmentStorage();
                return defaultAppointmentStorage;
            }
        }

        static MVCxAppointmentStorage CreateDefaultAppointmentStorage()
        {
            MVCxAppointmentStorage appointmentStorage = new MVCxAppointmentStorage();
            appointmentStorage.Mappings.AppointmentId = "FCalendarID";
            appointmentStorage.Mappings.Start = "FBeginDate";
            appointmentStorage.Mappings.End = "FEndDate";
            appointmentStorage.Mappings.Subject = "FTitle";
            appointmentStorage.Mappings.Description = "FContents";
            //appointmentStorage.Mappings.Location = "Location";
            //全天事件
            appointmentStorage.Mappings.AllDay = "IsAllDay";
            //是否提醒
            appointmentStorage.CustomFieldMappings.Add("WakeStr", "WakeStr");
            //优先级
            appointmentStorage.CustomFieldMappings.Add("FPri", "FPri");
            appointmentStorage.CustomFieldMappings.Add("isremind", "FIsWake");
            //appointmentStorage.Mappings.Type = "EventType";
            //appointmentStorage.Mappings.RecurrenceInfo = "RecurrenceInfo";
            //提醒
            appointmentStorage.Mappings.ReminderInfo = "ReminderInfo";
            //appointmentStorage.Mappings.Label = "Label";
            //appointmentStorage.Mappings.Status = "Status";
            appointmentStorage.Mappings.ResourceId = "FEmplNo";
            return appointmentStorage;
        }

        static MVCxResourceStorage defaultResourceStorage;
        public static MVCxResourceStorage DefaultResourceStorage
        {
            get
            {
                if (defaultResourceStorage == null)
                    defaultResourceStorage = CreateDefaultResourceStorage();
                return defaultResourceStorage;
            }
        }
        static MVCxResourceStorage CreateDefaultResourceStorage()
        {
            MVCxResourceStorage resourceStorage = new MVCxResourceStorage();
            resourceStorage.Mappings.ResourceId = "FEmplNo";
            resourceStorage.Mappings.Caption = "FEmpName";
            return resourceStorage;
        }
    }


}


